//------------------------------------------------------------------------------
// The contents of this file are subject to the nopCommerce Public License Version 1.0 ("License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at  http://www.nopCommerce.com/License.aspx. 
// 
// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. 
// See the License for the specific language governing rights and limitations under the License.
// 
// The Original Code is nopCommerce.
// The Initial Developer of the Original Code is NopSolutions.
// All Rights Reserved.
// 
// Contributor(s): _______. 
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Text;
using Tathata.Common.BLL.Managers;
using Tathata.Common.BLL.EntityCollections;

namespace Tathata.Common.BLL.Entities
{
    /// <summary>
    /// Represents a customer
    /// </summary>
    public class Customer : BaseEntity
    {
        #region Ctor
        /// <summary>
        /// Creates a new instance of the Customer class
        /// </summary>
        public Customer()
        {
        }
        #endregion

        #region Properties
        /// <summary>
        /// Gets or sets the customer identifier
        /// </summary>
        public int CustomerID { get; set; }

        /// <summary>
        /// Gets or sets the customer GUID
        /// </summary>
        public Guid CustomerGUID { get; set; }

        /// <summary>
        /// Gets or sets the email
        /// </summary>
        public string Email { get; set; }

        /// <summary>
        /// Gets or sets the password hash
        /// </summary>
        public string PasswordHash { get; set; }

        /// <summary>
        /// Gets or sets the salt key
        /// </summary>
        public string SaltKey { get; set; }

        /// <summary>
        /// Gets or sets the affiliate identifier
        /// </summary>
        public int AffiliateID { get; set; }

        /// <summary>
        /// Gets or sets the last shipping method identifier
        /// </summary>
      

        /// <summary>
        /// Gets or sets the language identifier
        /// </summary>
        public int LanguageID { get; set; }

        /// <summary>
        /// Gets or sets the currency identifier
        /// </summary>
        public int CurrencyID { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether the customer is administrator
        /// </summary>
        public bool IsAdmin { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether the customer is active
        /// </summary>
        public bool Active { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether the customer has been deleted
        /// </summary>
        public bool Deleted { get; set; }

        /// <summary>
        /// Gets or sets the date and time of customer registration
        /// </summary>
        public DateTime RegistrationDate { get; set; }
        #endregion

        #region Custom Properties

        /// <summary>
        /// Gets the customer attributes
        /// </summary>
        public CustomerAttributeCollection CustomerAttributes
        {
            get
            {
                return CustomerAttributeManager.GetAllByCustomerID(CustomerID);
            }
        }

        /// <summary>
        /// Gets the language
        /// </summary>
        public Language Language
        {
            get
            {
                return LanguageManager.GetByLanguageID(LanguageID);
            }
        }

        /// <summary>
        /// Gets the currency
        /// </summary>
        public Currency Currency
        {
            get
            {
                return CurrencyManager.GetByCurrencyID(CurrencyID);
            }
        }


        /// <summary>
        /// Gets the customer full name
        /// </summary>
        public string FullName
        {
            get
            {
                string firstName = string.Empty;
                string lastName = string.Empty;
                Customer customer = CustomerManager.GetByCustomerID(CustomerID);
                if (customer != null)
                {
                    CustomerAttributeCollection customerAttributes = CustomerAttributes;
                    CustomerAttribute firstNameAttr = customerAttributes.FindAttribute("FirstName", customer.CustomerID);
                    if (firstNameAttr != null)
                        firstName = firstNameAttr.Value;

                    CustomerAttribute lastNameAttr = customerAttributes.FindAttribute("LastName", customer.CustomerID);
                    if (lastNameAttr != null)
                        lastName = lastNameAttr.Value;
                }
                if (String.IsNullOrEmpty(firstName))
                    return lastName;
                else
                    return string.Format("{0} {1}", firstName, lastName);
            }
        }
        #endregion
    }

}